<template>
  <div class="goods-tabs">
    <nav>
      <a
        @click="changeTab('detail')"
        :class="{ active: activeMenu === 'detail' }"
        href="javascript:;"
        >商品详情</a
      >
      <a
        @click="changeTab('comment')"
        :class="{ active: activeMenu === 'comment' }"
        href="javascript:;"
        >商品评价<span>600+</span></a
      >
    </nav>
    <!-- 这个位置显示对应的组件 GoodsDetail 或者 GoodsComment -->
    <!--
      动态组件：动态切换不同的组件
      用法：必须是动态绑定 :is="变量" （变量值是切换组件的标签名）
     -->
    <keep-alive include="GoodDetail">
      <component :is="activeMenu" />
    </keep-alive>
  </div>
</template>
<script>
import GoodDetail from './goods-detail.vue'
import GoodComment from './goods-comment.vue'
import { ref } from 'vue'
export default {
  name: 'GoodsTabs',
  components: {
    detail: GoodDetail,
    comment: GoodComment
  },
  setup () {
    // 商品详情 detail 商品评价 comment
    const activeMenu = ref('comment')
    // 当前选中的组件的标签名
    // const seledTagName = ref('')
    // 切换tab
    const changeTab = (tab) => {
      activeMenu.value = tab
    }
    return { activeMenu, changeTab }
  }
}
</script>
<style scoped lang="less">
.goods-tabs {
  min-height: 600px;
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: @priceColor;
        font-size: 16px;
        margin-left: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }
      &.active {
        &::before {
          content: "";
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: @xtxColor;
        }
      }
    }
  }
}
</style>
